package com.loop.dateTime;

import sun.java2d.pipe.SpanShapeRenderer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateDemo {
    public static void main(String[] args)  {
        /*Date date = new Date();
        System.out.println(date);
        Date date1 = new Date(0);
        date1.setTime(5000);
        System.out.println(date1.getTime());
        System.out.println(date1);*/
        dateFormatDemo();
    }

    public static void dateFormatDemo()  {
        //无参构造
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
        Date date = new Date();
        String format = simpleDateFormat.format(date);
        System.out.println(format);

        //自定义格式的构造
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format1 = simpleDateFormat1.format(date);
        System.out.println(format1);

        //字符串类型转成Date类型
        Date date1 = null;
        try {
            date1 = simpleDateFormat1.parse("2022-01-22 16:14:29");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(date1);
    }
}
